<template>
  <div class="toolbox-container">
    <div v-if="isToolShow" class="tools">
      <div class="tool-node" @click="handleMeasureShow">
        <svg-icon icon="measure"></svg-icon>
        <div class="title-node" :class="{'active': activeNode=='distance'||activeNode=='area'}" title="测量工具">
        </div>
        <div v-if="mapToolShow" class="child-tools">
          <div class="child-node" @click="handleMeasureLine" :class="{'active': activeNode=='distance'}" title="测量距离">
            <svg-icon icon="mea-distance"></svg-icon>
          </div>
          <div class="child-node" @click="handleMeasurePolygon" :class="{'active': activeNode=='area'}" title="测量面积">
            <svg-icon icon="mea-area"></svg-icon>
          </div>
        </div>
      </div>
      <!--<el-divider class="node-divider" direction="vertical"/>-->
      <div class="tool-node" @click="handleAddMarker" :class="{'active': activeNode=='marker'}" title="标记">
        <svg-icon icon="marker"></svg-icon>
      </div>
      <!--<el-divider class="node-divider" direction="vertical"/>-->
      <div class="tool-node" @click="handleToolNodeClick('clearScreen')" title="清屏">
        <svg-icon icon="clear-map"></svg-icon>
      </div>
    </div>
    <div class="btn" @click="handleShowTool">
      <svg-icon icon="tool-btn"/>
    </div>
  </div>
</template>

<script setup>
  import { ref, defineEmits, defineProps } from 'vue'
  import normalMarker from '../../assets/images/gis/marker_normal.png'

  const mapToolShow = ref(false)
  const emits = defineEmits([
    'deskRend',
    'addMarker',
    'markLine',
    'markFace',
    'markCircle',
    'measureLine',
    'measurePolygon',
    'clearScreen',
    'fullScreen',
    'toolShow'
  ])
  const visibleRendDialog = ref(false)
  const visibleMarkPointDialog = ref(false)
  const visibleMarkMapDialog = ref(false)
  const titleNode = ref('')
  const activeNode = ref('')
  const props = defineProps({
    isFullScreen: {
      type: Boolean,
      default: false
    },
    isToolShow: {
      type: Boolean,
      default: false
    }
  })

  const handleMeasureShow = () => {
    mapToolShow.value = !mapToolShow.value
  }

  const handleMeasurePolygon = () => {
    activeNode.value = 'area'
    emits('measurePolygon')
  }
  const handleMeasureLine = () => {
    activeNode.value = 'distance'
    emits('measureLine')
  }
  const handleMarkLine = (params) => {
    emits('markLine', params)
  }
  const handleMarkFace = (params) => {
    emits('markFace', params)
  }
  const handleMarkCircle = (params) => {
    emits('markCircle', params)
  }
  const handleAddMarker = () => {
    activeNode.value = 'marker'
    const params = {
      name: '标记点',
      description: '标记点',
      image: normalMarker, // 图标样式url
      width: 20,
      height: 20,
      colorStr: '#e5a935', //WHITE:图标原始颜色，
      size: 20,
      show: true
    }
    emits('addMarker', params)
  }

  const handleFullScreenClick = () => {
    emits('fullScreen')
    // 如果是全屏状态
    if (props.isFullScreen) {
      activeNode.value = ''
    } else {
      activeNode.value = 'full'
    }
  }
  const handleShowTool = () => {
    emits('toolShow')
    if (!props.isToolShow) {
      mapToolShow.value = false
    }
  }

  const handleToolNodeClick = (type) => {
    activeNode.value = ''
    mapToolShow.value = false
    switch (type) {
      case 'clearScreen':
        emits('clearScreen')
        break

      default:
        break
    }
  }
</script>

<style lang="scss" scoped>
  .toolbox-container {
    height: 39px;
    display: flex;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    /*font-style: italic;*/
    color: rgba(255, 255, 255, 1);

    .node-divider {
      margin: auto;
      text-align: center;
      width: 2px;
      height: 32px;
    }

    .btn {
      width: 39px;
      height: 39px;
      background: rgba(0, 0, 0, 0.7);
      border: 1px solid #00FFFF;
      /*border-radius: 5px;*/
      float: right;
      display: flex;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      cursor: pointer;
    }

    .tools {
      display: flex;
      /*height: 39px;*/
      /*background: rgba(19, 93, 159, 0.8);*/
      /*border: 1px solid #177fc6;*/
      /*border-radius: 5px;*/
      box-sizing: border-box;
      margin-right: 5px;

      .tool-node {
        width: 39px;
        height: 39px;
        display: flex;
        column-gap: 12px;
        padding-left: 8px;
        margin-left: 2px;
        text-align: center;
        background: rgba(0, 0, 0, 0.7);
        border: 1px solid #00FFFF;
        position: relative;
        align-items: center;
        cursor: pointer;

        &:active, &.active {
          color: #2dd1c5;
          background: #112C34;
        }

        .title-node {
          &:active, &.active {
            color: #2dd1c5;
            background: #112C34;
          }
        }

        .child-tools {
          width: 100%;
          display: flex;
          flex-direction: column;
          background: rgba(0, 0, 0, 0.7);
          border: 1px solid #00FFFF;
          border-radius: 5px;
          padding: 2px 5px 2px 5px;
          position: absolute;
          top: 30px;
          left: 0px;
          z-index: 2;

          .child-node {
            display: flex;
            column-gap: 13px;
            width: 100%;
            height: 39px;
            align-items: center;
            justify-content: center;
            cursor: pointer;

            &:active, &.active {
              color: #2dd1c5;
              background: #112C34;
            }
          }
        }
      }

      .last {
        border-left: none;
      }
    }

    .rend-dialog {
      position: absolute;
      top: 45px;
      left: -2px;
    }
  }
</style>
